class Idris2 < Formula
  desc "Pure functional programming language with dependent types"
  homepage "https://www.idris-lang.org/"
  url "https://github.com/idris-lang/Idris2/archive/v0.2.1.tar.gz"
  sha256 "7be16253c9592802f0ab1ebb1b635bd3e254577205e1fd7d8139b1683732fcc7"
  license "BSD-3-Clause"
  revision 1
  head "https://github.com/idris-lang/Idris2.git"

  bottle do
    cellar :any
    sha256 "4e850720481a3aa77a2447ae4da25b3a68ffb70c748c965dc4adf277aed65acf" => :big_sur
    sha256 "0dfa71945dc9e8199954880828412616e7472c0a72bce756fab0a0ef62b94472" => :catalina
    sha256 "09ccf3e0d6871d3898e80afa92fa83b2df63b8dedc21547777e8e58dfc2d1979" => :mojave
    sha256 "6641e4427bd78b544caf8f78fd72ff1faafd8f5439a8357f62e2311db891e146" => :high_sierra
  end

  depends_on "coreutils" => :build
  depends_on "chezscheme"

  def install
    ENV.deparallelize
    scheme = Formula["chezscheme"].bin/"chez"
    system "make", "bootstrap", "SCHEME=#{scheme}", "PREFIX=#{libexec}"
    system "make", "install", "PREFIX=#{libexec}"
    # idris2.so is an executable file generated by Idris2
    bin.install "#{libexec}/bin/idris2_app/idris2.so" => "idris2"
    lib.install_symlink Dir["#{libexec}/lib/*.dylib"]
  end

  test do
    (testpath/"hello.idr").write <<~EOS
      module Main
      main : IO ()
      main = putStrLn "Hello, Homebrew!"
    EOS

    system bin/"idris2", "hello.idr", "-o", "hello"
    assert_equal "Hello, Homebrew!",
                 shell_output("./build/exec/hello_app/hello.so").chomp
  end
end
